<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        收票
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">

</head>
<!--开票-->
<style>

</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>名称</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="name" v-model="billing.name"
                               lay-verify="required" placeholder="名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>纳税人识别号</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="taxpayerIdentificationNumber"
                               v-model="billing.taxpayerIdentificationNumber"
                               lay-verify="required" placeholder="纳税人识别号" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>地址、电话</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="addressAndTelephoneNumber" v-model="billing.addressAndTelephoneNumber"
                               placeholder="地址、电话" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>开户行和账号</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="bankAndAccountNumber" v-model="billing.bankAndAccountNumber"
                               placeholder="开户行和账号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>联系信息</label>
                    <div style="width: 70%" class="layui-input-inline ">
                        <input  autocomplete="off"  type="text" name="contactInformation" v-model="billing.contactInformation"
                               placeholder="联系信息" class="layui-input">
                    </div>
                </div>


                <div class=" layui-inline  layui-form-item">
                    <label class="layui-form-label">
                        <span class='x-red'>*</span>票面金额
                    </label>
                    <div class="layui-input-block">
                        <input  autocomplete="off"  type="number" name="faceValue" v-model="billing.faceValue" autocomplete="off"
                               placeholder="票面金额" class="layui-input" lay-verify="required">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label">
                        <span class='x-red'>*</span>票面税额
                    </label>
                    <div class="layui-input-block">
                        <input  autocomplete="off"  type="number" name="faceTax" v-model="billing.faceTax" autocomplete="off"
                               placeholder="票面税额" class="layui-input" lay-verify="required">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label">
                        <span class='x-red'>*</span>税点
                    </label>
                    <div class="layui-input-block">
                        <input  autocomplete="off"  type="number" name="taxPoint" v-model="billing.taxPoint" autocomplete="off"
                               placeholder="税点 %" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>开票日期</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="billingDate" v-model="billing.billingDate" id="billingDate"
                               lay-verify="required"
                               placeholder="开票日期" class="layui-input" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class='x-red'>*</span>票据类型
                    </label>
                    <div class="layui-input-block">
                        <select name="billType" lay-verify="required">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class='x-red'></span>关联凭据
                    </label>
                    <div class="layui-input-block">
                        <input  autocomplete="off"  type="text" name="associatedCredentials" v-model="billing.associatedCredentials"
                               autocomplete="off"
                               placeholder="关联凭据" class="layui-input">
                    </div>
                </div>

                <div class=" layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>摘要说明</label>
                    <div style="width: 70%" class="layui-input-inline">
                        <textarea name="remark" placeholder="请输入内容" v-model="billing.remark"
                                  class="layui-textarea"></textarea>
                    </div>
                </div>
                <br>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>票据附件</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="file" ref="billAttachment" @change="getFile($event,'billAttachment')"
                               name="billAttachment"
                               placeholder="票据附件" class="layui-input" style="display: none">

                        <img style="width: 100px" v-if="billing.billAttachment != null && billing.billAttachment != ''"
                             :src="bindSrcBillAttachment"
                             alt="xx" @click="uploadBillAttachment">
                        <img style="width: 100px" v-if="billing.billAttachment == null || billing.billAttachment == ''"
                             src="../../../images/upload.png"
                             alt="xx" @click="uploadBillAttachment">
                    </div>
                </div>


                <div class=" layui-form-item">
                    <label style="width: 20%" class="layui-form-label"> <span class='x-red'></span>签收回执图片</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="file" ref="pictureOfReceipt" @change="getFile($event,'pictureOfReceipt')"
                               name="pictureOfReceipt"
                               placeholder="签收回执图片" class="layui-input" style="display: none">

                        <img style="width: 100px"
                             v-if="billing.pictureOfReceipt != null && billing.pictureOfReceipt != ''"
                             :src="bindSrcPictureOfReceipt"
                             alt="xx" @click="uploadPictureOfReceipt">
                        <img style="width: 100px"
                             v-if="billing.pictureOfReceipt == null || billing.pictureOfReceipt == ''"
                             src="../../../images/upload.png"
                             alt="xx" @click="uploadPictureOfReceipt">
                    </div>
                </div>

                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>
                <!--</form>-->
                <div style="height:100px;"></div>
            </div>


        </div>

    </form>
</div>
<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script src="../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../js/vue.min.js" charset="utf-8"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;

            laydate.render({
                elem: '#billingDate', //指定元素
                trigger: 'click',
                type: 'datetime',
                done: function (value, date, endDate) {
                    vm.billing.billingDate = value
                }
            });

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.id = vm.billing.id;
                    form.billAttachment = vm.billing.billAttachment;
                    form.pictureOfReceipt = vm.billing.pictureOfReceipt;
                    vm.billing.id == null ? form.operationType = 'add' : form.operationType = 'edit';
                    form.nature = '收票';
                    // form.billAttachment = form.billAttachment.substring(0, form.billAttachment.length - 1);
                    // form.pictureOfReceipt = form.pictureOfReceipt.substring(0, form.billAttachment.length - 1);

                    let request = {
                        url: 'billFlow/addBillFlow',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();
                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });


        });


    const vm = new Vue({
        el: "#app",
        data: {
            billing: {
                id: null,
                name: null,
                taxpayerIdentificationNumber: null,
                addressAndTelephoneNumber: null,
                bankAndAccountNumber: null,
                contactInformation: null,
                billType: null,
                faceValue: null,
                billingDate: null,
                taxPoint: null,
                faceTax: null,
                associatedCredentials: null,
                associatedCredentialsId: null,
                remark: null,
                billAttachment: '',
                pictureOfReceipt: '',
                type: null,
                nature: null
            }
        },
        created() {

            if(recordId){

                let request = {
                    url: 'billFlow/findBillFlow',
                    data: {
                        userId: $userId,
                        recordId: recordId
                    },
                    method: "POST"
                };
                sendRequest(request, (res) => {
                    // console.log(res);
                    this.billing = res.data;
                })

            }



        },
        computed: {
            bindSrcBillAttachment() {
                return vm.billing.billAttachment.startsWith('upload') ? $baseUrl +
                    'other/viewUploadFile?id=' + vm.billing.billAttachment : '../../images/upload.png';
            },
            bindSrcPictureOfReceipt() {
                return vm.billing.pictureOfReceipt.startsWith('upload') ? $baseUrl +
                    'other/viewUploadFile?id=' + vm.billing.pictureOfReceipt : '../../images/upload.png';
            }
        },
        methods: {
            uploadBillAttachment() {
                this.$refs.billAttachment.click()
            },
            uploadPictureOfReceipt() {
                this.$refs.pictureOfReceipt.click()
            },
            getFile(event, type) {

                var file = event.target.files[0];

                let qualified = ".jpg .png .bmp .jpeg .gif .bmp";
                let fineName = file.name;
                if (!fineName.includes(".") || !qualified.includes(fineName.substr(fineName.lastIndexOf(".")))) {
                    layer.alert("上传类型错误，只支持.jpg .png .bmp");
                    return;
                }

                var formData = new FormData();
                formData.append('photo', file);
                formData.userId = $userId;
                $.ajax({
                    url: $baseUrl + "/other/fileUpload",
                    type: "post",
                    headers: {
                        "token": $token,
                    },
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (res) {
                        type === 'billAttachment' ? vm.billing.billAttachment = res.data :
                            vm.billing.pictureOfReceipt = res.data;
                        layer.alert(res.msg);
                    },
                    error: function (res) {
                        layer.alert(res.msg);
                    }
                });
            }
        },


    });

    setTimeout(() => {
        //修改状态
        let form = layui.form;
        //查发票类型
        let request = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'BILL_TYPE'
            },
            method: "POST",
        };
        sendRequest(request, (res) => {
            let billType = res.data;
            $.each(billType, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=billType]").append(opt);

            });

            $("select[name=billType]").val(vm.billing.billType);

            form.render('select');
        });
    }, 300)

</script>

</body>

</html>
